package rs.fon.is.music.services.rest.parsers;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import rs.fon.is.music.domain.MusicGroup;

import com.google.gson.JsonObject;

public class MusicGroupJsonParser {

	public static JsonObject serialize(MusicGroup group) {
		JsonObject groupJson = new JsonObject();
		String uri = group.getUri().toString();
		groupJson.addProperty("uri", uri);
		groupJson.addProperty("url", group.getUrl().toString());
		groupJson.addProperty("name", group.getName());
		groupJson.addProperty("image", group.getImage().toString());
		DateFormat format = new SimpleDateFormat("yyyy");
		if(group.getFoundingDate()!=null)
		groupJson.addProperty("foundingDate", format.format(group.getFoundingDate()));
		groupJson.addProperty("interactionCount", group.getInteractionCount());
		String id = uri.substring(uri.lastIndexOf('/')+1);
		groupJson.addProperty("albums", "http://localhost:8080/Music/api/groups/" + id + "/albums");
		groupJson.addProperty("tracks", "http://localhost:8080/Music/api/groups/" + id + "/recordings");
		return groupJson;
	}

}
